package by.amakarevich.services.impl;

import java.util.List;

import javax.inject.Inject;

import org.apache.commons.lang3.Validate;
import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.ProductDao;
import by.amakarevich.dataaccess.TambourDao;
import by.amakarevich.datamodel.Product;
import by.amakarevich.datamodel.Tambour;
import by.amakarevich.services.TambourService;

@Service
public class TambourServiceImpl implements TambourService {
	@Inject
	private TambourDao tambourDao;

	@Inject
	private ProductDao productDao;

	@Override
	public void createNewTambour(Tambour tambour, Product product) {
		Validate.isTrue(
				tambour.getId() == null,
				"This method should be called for 'not saved yet' profile only. Use UPDATE instead");
		tambour.setProduct(product);
		tambourDao.insert(tambour);
	}

	@Override
	public Tambour get(Long id) {
		return tambourDao.getById(id);
	}

	@Override
	public void updateTambour(Tambour tambour) {
		tambourDao.update(tambour);
	}

	@Override
	public void removeTambour(Long id) {

		tambourDao.delete(id);
		productDao.delete(id);

	}

	@Override
	public void deleteAll() {
		tambourDao.deleteAll();
		productDao.deleteAll();
	}
	
	@Override
	public List<Tambour> getAllTambour(){
		return tambourDao.getAllTambour();
	}
	
	@Override
	public Tambour getByProductId(Product product){
		return tambourDao.getByProductId(product);
	}
}
